home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
refs51.zip
/
REFS51.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1989-11-06
|
18KB
|
639 lines
{$R-} {Range checking off}
{$B-} {Boolean short circuiting off}
{$S+} {Stack checking on}
{$I+} {I/O checking on}
{$N-} {No numeric coprocessor}
program refs;
(*REFS-- find and list references in manuscripts
COPYRIGHT 1985 by Ross A. Alford
All commercial rights reserved. This software is released for
nonprofit distribution only. Any commercial distribution should be
undertaken only with the express consent of the copyright holder:
Ross A. Alford
Department of Zoology
Duke University
Durham, NC 27706
...[decvax, ihnp4, akgua]!mcnc!ecsvax!alford
REFS finds references in scientific manuscripts. It will list references
found and the number of times they are occur to a file, a printer, or
the system console. It should work with references of the forms:
Smith, 1980 |Smith (1980)
Smith, 1980a |Smith (1980a)
Smith, 1980a, b |Smith (1980a, b)
Smith, 1980a, 1980b |Smith (1980a, 1980b)
Smith and Smith, 1980 |Smith and Smith (1980)
Smith et al., 1980 |Smith et al. (1980)
Smith's 1980 |Smith's (1980)
Smith, Smith, and Smith, 1980 |Smith, Smith, and Smith (1980)
Smith-Smythe and Smith 1980
Smith {\it et al.} (1980) ( Added by JM-M, see below )
\fnote{Smith (1980)} ( ditto )
and with most any similar style. It also allows the last digit of the year
to be replaced by a letter, as Smith, 198x, for cases where the exact date
is uncertain. It may not work entirely properly on references in tabular
formats, specifically if a reference of the form Smith 1980a,b is split
between lines so that the 'b' is widely separated from the 'a'.
Month, year dates, as July, 1980, also are treated as references. You never
know when some person might have the same name as a month.
Operating the program is simple, and is documented in the msgexit function.
Just run the program with no parameters for a description. I apologize for
the paucity of comments, but after all this is self-documenting Pascal :-)
Please let me know of any bugs found, bug fixes made, or improvements
made.
Ross Alford*)
(* REVISED
Version: 1.5j
Revisions by: Jeff_MacKie-Mason@um.cc.umich.edu
Dept. of Economics
Univ. of Michigan
Ann Arbor, MI 48109
Revision date: 18 November 1987
6 November 1989
Revision abstract:
1) Upgraded for compilation with Turbo Pascal v. 4.0.
Actually, I used the Turbo3 standard unit, so version 3.0
definitions are mostly in effect, but compiling with v. 4.0
leads to a smaller executable.
Had to change DOS device names, and add a result parameter
to blockread to handle incomplete reads.
2) Rewrote GetArg function to use ParamStr (especially since
it is illegal to use CSeg in an absolute declaration)
3) Changed MemAvail to longint, converted returned bytes to paragraphs,
deleted reference to Turbo3 unit, recompiled with Turbo5. (11/6/89)
4) Modified logic to recognize refs that begin \fnote's,
and refs of the form Baker {\it et al.} (1980) in TeX. (11/6/89)
5) Modified logic to recognize \footnote and refs of form
Baker {\em et al.} (1980) for LaTex. (11/7/89)
*)
Uses
Crt;
const charsect = 128;
namelen = 60;
version = '1.3';
jversion = '5.1j';
type fnamestr = string[14];
msgstr = string[80];
tabletyp = array[0..127] of boolean;
buftype = array[1..CHARSECT] of byte;
nametyp = string[NAMELEN];
datetyp = string[5];
refptr = ^reference;
reference = record
next : refptr;
name : string[NAMELEN];
number : integer
end;
sectptr = ^sectrec;
sectrec = record
next : sectptr;
previous : sectptr;
data : buftype
end;
var inf : file;
i,j,ptrsave,sinceref : integer;
c : byte;
oldyear,year : datetyp;
xtra,name,tempname,oldname : nametyp;
closeparen,notfound : boolean;
outfname,infile : fnamestr;
reflist : refptr;
result : word; { new in v.1.3j}
{intentional global variables- to speed things up}
outf : text;
lowcase,isupcase,otherbad,letter,number : tabletyp;
cursectnum,numinfile : integer;
infopen,outfopen,hitnumber,comma,done : boolean;
sector,savesect : sectptr; {current sector in use}
ptr,saveptr : integer; {location within sector}
{---------exit gracefully with info---------------------------------------}
procedure msgexit(msg : msgstr);
begin
if infopen then close(inf);
if outfopen then close(outf);
writeln;
if msg <> '' then
begin
writeln(chr(7),msg);
writeln
end;
writeln('REFS finds references in the name, date form in manuscripts.');
writeln;
writeln('To run REFS enter a command line like:');
writeln;
writeln('A>refs infile {outfile}');
writeln;
writeln('Where infile is a DOS filename of the form drive:filename.ext');
writeln;
writeln('and outfile can be either a disk file, given in the same format ');
writeln('as infile, or can be given as CON to send output to the CRT screen');
writeln('or LPT1 to send output to the DOS list device.');
writeln;
writeln('If outfile is not specified, a file of the same base name as infile');
writeln('but with the extension .REF, will be created on the same drive that');
writeln('infile is read from.');
writeln;
halt
end;
{---------------------read a sector into a sector buffer-------------------}
procedure readsector(var sector : sectptr);
begin
if cursectnum < numinfile then
begin
blockread(inf,sector^.data,1);
cursectnum := succ(cursectnum)
end
else done := TRUE
end;
{------------------------get a new sector buffer node-------------------}
procedure getsectnode(var sector : sectptr);
var n : longint;
begin
n := memavail div 16;
if ((n and $7fff) < 512) then msgexit('Out of memory during sector read');
new(sector);
sector^.next := NIL;
sector^.previous := NIL
end;
{----------------return the character currently pointed to-------------}
function curbyte : byte; {uses globals sector and ptr}
begin
curbyte := sector^.data[ptr] and $7f
end;
{---------get next character, read a new sector if needed--------------}
function nextbyte : byte; {uses globals sector and ptr}
var tempsec : sectptr;
t : byte;
begin
ptr := succ(ptr);
if ptr > 128 then
if sector^.next = NIL then
begin
tempsec := sector^.previous;
if tempsec = NIL then getsectnode(tempsec);
readsector(tempsec);
if not done then
begin
tempsec^.previous := sector;
sector^.previous := NIL;
sector^.next := tempsec;
tempsec^.next := NIL;
sector := tempsec;
ptr := 1
end
end
else begin
tempsec := sector^.next;
tempsec^.next := NIL;
tempsec^.previous := sector;
sector^.previous := NIL;
sector := tempsec;
ptr := 1;
end;
t := sector^.data[ptr];
if t = 26 then done := TRUE;
nextbyte := t and $7f
end;
{--------------------return previous character--------------------}
function prevbyte : byte; {uses globals sector and ptr}
var tempsec : sectptr;
ch : byte;
begin
ptr := pred(ptr);
if ptr < 1 then
begin
if sector^.previous <> NIL then
begin
tempsec := sector^.previous;
tempsec^.next := sector;
tempsec^.previous := NIL;
sector^.next := NIL;
sector := tempsec;
ptr := 128
end
end;
if (ptr < 1) then
prevbyte := 0
else prevbyte := sector^.data[ptr] and $7f
end;
{return previous alphabetic word. Set the global 'comma'=TRUE if a comma
follows it. Set the global 'hitnumber' TRUE if a digit is encountered.
Return no word if any of the characters for which corres